package com.ruoyi.resume.mapper;

import com.ruoyi.resume.domain.model.ResumeAnalysis;
import org.apache.ibatis.annotations.*;

@Mapper
public interface ResumeAnalysisMapper {

    // 插入分析内容
    @Insert("INSERT INTO resume_analysis " +
            "(resume_id, strength_1, strength_2, strength_3, weakness_1, weakness_2, weakness_3, " +
            "overall_evaluation, question_1, question_2, question_3, created_at, updated_at) " +
            "VALUES (#{resumeId}, #{strength1}, #{strength2}, #{strength3}, #{weakness1}, " +
            "#{weakness2}, #{weakness3}, #{overallEvaluation}, #{question1}, #{question2}, #{question3}, " +
            "CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)")
    @Options(useGeneratedKeys = true, keyProperty = "analysisId")
    int insertResumeAnalysis(ResumeAnalysis resumeAnalysis);

    // 根据简历ID查询分析内容
    @Select("SELECT * FROM resume_analysis WHERE resume_id = #{resumeId}")
    @Results({
            @Result(column = "analysis_id", property = "analysisId"),
            @Result(column = "resume_id", property = "resumeId"),
            @Result(column = "strength_1", property = "strength1"),
            @Result(column = "strength_2", property = "strength2"),
            @Result(column = "strength_3", property = "strength3"),
            @Result(column = "weakness_1", property = "weakness1"),
            @Result(column = "weakness_2", property = "weakness2"),
            @Result(column = "weakness_3", property = "weakness3"),
            @Result(column = "overall_evaluation", property = "overallEvaluation"),
            @Result(column = "question_1", property = "question1"),
            @Result(column = "question_2", property = "question2"),
            @Result(column = "question_3", property = "question3"),
            @Result(column = "created_at", property = "createdAt"),
            @Result(column = "updated_at", property = "updatedAt")
    })
    ResumeAnalysis getResumeAnalysisByResumeId(@Param("resumeId") Integer resumeId);

    @Select("SELECT COUNT(*) > 0 FROM resume_analysis WHERE resume_id = #{resumeId}")
    boolean existsResumeAnalysisByResumeId(@Param("resumeId") Integer resumeId);

    @Delete("DELETE FROM resume_analysis WHERE resume_id = #{resumeId}")
    void deleteResumeAnalysisByResumeId(@Param("resumeId") Integer resumeId);
}

